package com.example.chenkai10;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


    Button button;
    Bundle bundle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        bundle = new Bundle();
        bundle.putString("name","Jay");
        bundle.putInt("age",20);

        final Intent intent = new Intent(this,MainActivity2.class);

        intent.putExtras(bundle);

        button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {

                startActivityForResult(intent,99);

            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==99&&resultCode==88){
            Toast.makeText(this,"这是一个回调的例子.",Toast.LENGTH_LONG).show();
            TextView textView = findViewById(R.id.TextView2);
            textView.setText("回调成功!");
        }

    }
}